package com.nmmhu.bean.keeper;
import com.nmmhu.annotation.AnimalAno;
import com.nmmhu.bean.animals.Animal;
import com.nmmhu.bean.animals.Animals;
import com.nmmhu.bean.animals.bam.BirdAnimals;
import java.lang.reflect.Field;

/**
 * @author nmm
 * @date 2024-04-2024/4/4
 * @deriction 饲养员
 */
public  class Keeper <E extends Animal> {
    private  E MyAnimal;//接收的动物
    private  String KeeperName;//饲养员名字
    private String AnimalName;//动物名
    private Class AnimalClazz;//动物Clazz 实例
    private AnimalAno annotation;//动物注解

    public Keeper(E myAnimal,String name) {
        MyAnimal = myAnimal;
        this.KeeperName=name;

        Class<? extends Animal> AnimalClazz = MyAnimal.getClass();
        this.AnimalClazz=AnimalClazz;//拿到动物实例

        AnimalAno annotation = AnimalClazz.getAnnotation(AnimalAno.class);
        this.annotation=annotation;//拿到动物某的注解

        try {
            Field nameFiled = AnimalClazz.getSuperclass().getDeclaredField("name");
            nameFiled.setAccessible(true);
            this.AnimalName= (String) nameFiled.get(MyAnimal);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public  void   feeding(){
        System.out.println(String.format("饲养员%S正在喂养%S中..........",KeeperName,this.AnimalName));
        MyAnimal.eat();
    };//喂食

    public    void   check(){
        System.out.println("饲养员"+this.KeeperName+"正在巡查中..........");
        if (annotation.EnsureEatMdc()){
            System.out.println(this.AnimalName+"已经吃过药了。。。");
        }else {
            System.out.println(this.AnimalName+"还未吃药");
        }
    };//巡检


    public    void   bodyCheck(){
        System.out.println(String.format("饲养员%S正在对%S检查身体中..........",this.KeeperName,AnimalName));
        if (annotation.EnsureHealthy().equals("好")) {
            System.out.println(AnimalName+"身体嘎嘎好.........");
        }else {
            System.out.println(AnimalName+"需要特别关照");
        }
    };//体检

}